<template>
  <div class="container">
    <div class="header1" style="padding: 10px 0px">
      <div style="display: flex; justify-content: space-between">
        <div style="display: flex; justify-content: start">
          <a-button class="hte-btn" @click="edit">编辑</a-button>
          <a-button class="hte-btn" plain @click="handleReload">刷新</a-button>
        </div>
        <div style="display: flex; justify-content: end">
          <a-input-search v-model="searchForm.keyword" @search="handleToSearch" placeholder="请按照关键字进行搜索" />
          <!-- <a-button class="hte-btn del-btn" @click="showSearchForm = true">高级查询</a-button> -->
        </div>
      </div>
      <!-- <a-modal
          :visible="showSearchForm"
          width="70vw"
          :bodyStyle="{ padding: '10px' }"
          title="高级查询"
          @ok="handleToSearch"
          @cancel="showSearchForm = false"
        >
          <a-form-model
            ref="ruleForm"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
            @keyup.enter.native="handleToSearch"
          >
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="接收人">
                  <a-input allow-clear v-model="searchForm.toUser" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="消息标题">
                  <a-input allow-clear v-model="searchForm.title" />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="消息内容">
                  <a-input allow-clear v-model="searchForm.content" />
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </a-modal> -->
    </div>
    <div class="content-list">
      <a-table
        :columns="columns"
        :data-source="records"
        rowKey="id"
        bordered
        :pagination="false"
        :customRow="customRow"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
        <template slot="contentRender" slot-scope="text, record">
          <ArticleContent :key="record.id" ref="ArticleContent" btnText='查看详情' :articleNo="record.articleNo"/>
        </template>
      </a-table>
      <a-pagination
        show-size-changer
        :default-current="1"
        :total="searchForm.total"
        @change="pageChange"
        @showSizeChange="onShowSizeChange"
        :show-total="(total) => `共 ${total} 条记录`"
      />
    </div>
    
  </div>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import { formatDate, parseTime } from '@/utils/util'
import { UtilsMixin } from '@/mixins/UtilsMixin'
import { TableMixin } from '@/mixins/TableMixin'
import { Modal } from 'ant-design-vue'
export default {
  mixins: [UtilsMixin, TableMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    ArticleContent: () => import('@/views/back/article/ArticleContent'),
  },
  data() {
    return {
      currUserId: this.$store.getters.userInfo.username,
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ContractReportInfo',
      },
      urls: {
        list: '/hteSystemArticle/page',
      },
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      keywordType: '1',
      json: {},
      record: {},
      records: [],
      columns: [
        {
          title: 'ID',
          dataIndex: 'id',
          width: '100px',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '文章标题',
          dataIndex: 'title',
          width: '150px',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '消息内容',
          dataIndex: 'content',
          width: '150px',
          align: 'center',
          ellipsis: true,
          scopedSlots: { customRender: 'contentRender' },
        },
        {
          title: '创建人',
          dataIndex: 'createUser',
          width: '150px',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          align: 'center',
          width: '100px',
          ellipsis: true,
        },
        {
          title: '更新人',
          dataIndex: 'modifyUser',
          align: 'center',
          width: '100px',
          ellipsis: true,
        },
        {
          title: '更新时间',
          dataIndex: 'modifyTime',
          align: 'center',
          width: '100px',
          ellipsis: true,
        },
      ],
      showSearchForm: false,
      selectedRowKeys: [],
      selectedRows: [],
    }
  },
  async mounted() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      postAction(this.urls.list, this.searchForm).then((res) => {
        if (res.success) {
          this.records = res.result.records
          this.$set(this.searchForm, 'total', res.result.total)
        } else {
          this.$message.error('查询数据错误:' + res.message)
        }
      })
    },

    handleReload() {
      this.fetchList()
    },
    handleToSearch() {
      this.searchForm.pageNo = 1
      this.showSearchForm = false
      this.fetchList()
    },
    handleExport() {
      this.searchForm.selectedIds = this.selectedRowKeys.join(',')
      let url = process.env.VUE_APP_API_BASE_URL + '/hteSystemArticle/export?1=1'
      this.handleExportXls(parseTime(new Date(), '{y}{m}{d}') + '《文章列表》', url, this.searchForm)
    },
    edit() {
      if (this.selectedRowKeys.length >1) {
        this.$message.warning('请选择单条记录进行操作')
        return
      }
      if (this.selectedRowKeys.length == 1) {
        this.$router.push('/articleEdit?id=' + this.selectedRowKeys[0])
      } else {
        this.$router.push('/articleEdit')
      }
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.container {
  .content {
    margin-top: 20px;

    section {
      margin-bottom: 18px;

      .section-table {
        .add-btn {
          margin-left: 0;
          margin-bottom: 10px;
        }

        /deep/ .a-upload__input {
          display: none !important;
        }
      }
    }
  }
}

.tips-box {
  margin-top: 32px;

  .add-btn {
    width: 180px;
    height: 40px;
    line-height: 40px;
    background-color: #4095e4;
    border-radius: 2px;
  }
}
/deep/ .el-upload__input {
  display: none !important;
}
</style>
